package com.cuz.hot100;

import com.cuz.daileetcode.utils.ArrayUtils;

public class Q75sortColors {
    public static void main(String[] args) {
        int[] ints = {1,0, 0,1, 2, 2, 1, 1, 1, 2, 0, 1, 1, 0};
        sortColors1(ints);
        ArrayUtils.print(ints);
    }

    public static void sortColors1(int[] nums) {
        if (nums == null || nums.length == 0) {
            return;
        }
        //0-zero 都是0
        int zero = 0;
        //one - zero 都是1
        int one = 0;
        //zero nums.length - 1 都是2
        int two = nums.length - 1;
        while (one <= two) {
            if (nums[one] == 0) {
                int temp = nums[one];
                nums[one] = nums[zero];
                nums[zero] = temp;
                zero++;
                one++;
            } else if (nums[one] == 1) {
                one++;
            } else {
                int temp = nums[two];
                nums[two] = nums[one];
                nums[one] = temp;
                two--;
            }
        }
    }
}
